more concise automatic names for formats
authorØyvind Kolås <ok@src.gnome.org>
Fri, 9 Sep 2005 11:07:52 +0000 (11:07 +0000)
committerØyvind Kolås <ok@src.gnome.org>
Fri, 9 Sep 2005 11:07:52 +0000 (11:07 +0000)
ChangeLog
babl/babl-format.c
babl/base/model-lab.c [deleted file]
babl/base/model-rgb.c
babl/base/model-ycbcr.c

index 064f3b0bb2ac78d08fbc2e5aa4a42d48fc1540f9..d6aa9ae90c09f9cd7e67508b944329694c9005a9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2005-09-09  Øyvind Kolås  <pippin@gimp.org>
+
+       * babl/babl-format.c: (create_name): Create shorter names when
+       the format uses a single datatype and the components are listed in
+       model order.
+       * babl/base/model-lab.c: removed.
+       * babl/base/model-rgb.c: (formats),
+       * babl/base/model-ycbcr.c: (formats): Use automatic names for formats.
+
 2005-09-09  Øyvind Kolås  <pippin@gimp.org>
 
        * babl/babl-classes.h: added error to BablConversion.
index 606105f14280e88ed6bb5a7ec8c4b1353286e6fd..56ad171296c1ee89bd5d729b4ff0467d490d46aa 100644 (file)
@@ -115,11 +115,50 @@ create_name (BablModel      *model,
              BablType      **type)
 {
   char *p = &buf[0];
+  int   i;
+  int   same_types=1;
+  BablType **t=type;
+  BablType *first_type = *type;
+  BablComponent **c1=component;
+  BablComponent **c2=model->component;
 
+  
   sprintf (p, "%s ", model->instance.name);
   p+=strlen (model->instance.name) + 1;
 
-  while (components--)
+  i=components;
+  while (i--)
+    {
+      if (first_type != *t)
+        {
+          same_types=0;
+          break;
+        }
+      t++;
+    }
+
+  i=components;
+  while (i--)
+    {
+      if (*c1 != *c2)
+        {
+          same_types=0;
+          break;
+        }
+      c1++;
+      c2++;
+    }
+
+
+  if (same_types)
+    {
+      sprintf (p, "%s", first_type->instance.name);
+      return buf;
+    }
+
+  i=components;
+
+  while (i--)
     {
       sprintf (p, "(%s as %s) ", 
          (*component)->instance.name,
diff --git a/babl/base/model-lab.c b/babl/base/model-lab.c
deleted file mode 100644 (file)
index 5bebf13..0000000
+++ /dev/null
@@ -1,229 +0,0 @@
-/* babl - dynamically extendable universal pixel conversion library.
- * Copyright (C) 2005, Øyvind Kolås.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General
- * Public License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
- * Boston, MA 02111-1307, USA.
- */
-
-#include <string.h>
-#include "babl.h"
-#include "util.h"
-#include "cpercep.h"
-
-static void components    (void);
-static void models        (void);
-static void conversions   (void);
-static void formats       (void);
-
-void
-babl_base_model_lab (void)
-{
-  cpercep_init  ();
-  components    ();
-  models        ();
-  conversions   ();
-  formats       ();
-}
-
-static void
-components (void)
-{
-  babl_component_new (
-   "CIE L",
-   "id",    BABL_CIE_L,
-   NULL);
-
-  babl_component_new (
-   "CIE a",
-   "id",    BABL_CIE_A,
-   "chroma",
-   NULL);
-
-  babl_component_new (
-   "CIE b",
-   "id",    BABL_CIE_B,
-   "chroma",
-   NULL);
-}
-
-static void
-models (void)
-{
-  babl_model_new (
-    "CIE Lab",
-    "id", BABL_CIE_LAB,
-    babl_component_id (BABL_CIE_L),
-    babl_component_id (BABL_CIE_A),
-    babl_component_id (BABL_CIE_B),
-    NULL);
-
-  babl_model_new (
-    "CIE Lab alpha",
-    "id", BABL_CIE_LAB_ALPHA,
-    babl_component_id (BABL_CIE_L),
-    babl_component_id (BABL_CIE_A),
-    babl_component_id (BABL_CIE_B),
-    babl_component_id (BABL_ALPHA),
-    NULL);
-}
-
-static void
-rgb_to_lab (int    src_bands,
-            void **src,
-            int   *src_pitch,
-            int    dst_bands,
-            void **dst,
-            int   *dst_pitch,
-            int    n)
-{
-  BABL_PLANAR_SANITY
-
-  while (n--)
-    {
-      double red   = *(double*)src[0];
-      double green = *(double*)src[1];
-      double blue  = *(double*)src[2];
-
-      double L, a, b;
-
-      cpercep_rgb_to_space (red, green, blue, &L, &a, &b);
-
-      *(double*)dst[0] = L;
-      *(double*)dst[1] = a;
-      *(double*)dst[2] = b;
-
-      if (dst_bands > 3)               /* alpha passthorugh */
-        *(double*)dst[3] = (src_bands>3)?*(double*)src[3]:1.0;
-
-      BABL_PLANAR_STEP
-    }
-}
-
-static void
-lab_to_rgb (int    src_bands,
-            void **src,
-            int   *src_pitch,
-            int    dst_bands,
-            void **dst,
-            int   *dst_pitch,
-            int    n)
-{
-  BABL_PLANAR_SANITY
-
-  while (n--)
-    {
-      double L = *(double*)src[0];
-      double a = *(double*)src[1];
-      double b = *(double*)src[2];
-
-      double red, green, blue;
-
-      cpercep_space_to_rgb (L, a, b, &red, &green, &blue);
-
-      *(double*)dst[0] = red;
-      *(double*)dst[1] = green;
-      *(double*)dst[2] = blue;
-
-      if (dst_bands > 3)               /* alpha passthorugh */
-        *(double*)dst[3] = (src_bands>3)?*(double*)src[3]:1.0;
-
-      BABL_PLANAR_STEP
-    }
-}
-
-static void
-conversions (void)
-{
-  babl_conversion_new (
-    "babl-base: rgba to cie-lab",
-    "source",      babl_model_id (BABL_RGBA),
-    "destination", babl_model_id (BABL_CIE_LAB),
-    "planar",      rgb_to_lab,
-    NULL
-  );
-  babl_conversion_new (
-    "babl-base: cie-lab to rgba",
-    "source",      babl_model_id (BABL_CIE_LAB),
-    "destination", babl_model_id (BABL_RGBA),
-    "planar",      lab_to_rgb,
-    NULL
-  );
-  babl_conversion_new (
-    "babl-base: rgb to cie-lab",
-    "source",      babl_model_id (BABL_RGB),
-    "destination", babl_model_id (BABL_CIE_LAB),
-    "planar",      rgb_to_lab,
-    NULL
-  );
-  babl_conversion_new (
-    "babl-base: cie-lab to rgb",
-    "source",      babl_model_id (BABL_CIE_LAB),
-    "destination", babl_model_id (BABL_RGB),
-    "planar",      lab_to_rgb,
-    NULL
-  );
-  babl_conversion_new (
-    "babl-base: rgba to cie-lab-float",
-    "source",      babl_model_id (BABL_RGBA),
-    "destination", babl_model_id (BABL_CIE_LAB_ALPHA),
-    "planar",      rgb_to_lab,
-    NULL
-  );
-  babl_conversion_new (
-    "babl-base: cie-lab-float to rgba",
-    "source",      babl_model_id (BABL_CIE_LAB_ALPHA),
-    "destination", babl_model_id (BABL_RGBA),
-    "planar",      lab_to_rgb,
-    NULL
-  );
-}
-
-static void
-formats (void)
-{
-  babl_format_new (
-    "cie-lab-float",
-    "id", BABL_LAB_FLOAT,
-    babl_model_id     (BABL_CIE_LAB),
-    babl_type_id      (BABL_FLOAT),
-    babl_component_id (BABL_CIE_L), 
-    babl_component_id (BABL_CIE_A), 
-    babl_component_id (BABL_CIE_B),
-    NULL);
-
-  babl_format_new (
-    "cie-lab-u8",
-    "id", BABL_LAB_U8,
-    babl_model_id     (BABL_CIE_LAB),
-    babl_type_id      (BABL_U8_CIE_L),
-    babl_component_id (BABL_CIE_L),
-    babl_type_id      (BABL_U8_CIE_AB),
-    babl_component_id (BABL_CIE_A), 
-    babl_type_id      (BABL_U8_CIE_AB),
-    babl_component_id (BABL_CIE_B),
-    NULL);
-
-  babl_format_new (
-    "cie-lab-u16",
-    "id", BABL_LAB_U16,
-    babl_model_id     (BABL_CIE_LAB),
-    babl_type_id      (BABL_U16_CIE_L),
-    babl_component_id (BABL_CIE_L),
-    babl_type_id      (BABL_U16_CIE_AB),
-    babl_component_id (BABL_CIE_A), 
-    babl_type_id      (BABL_U16_CIE_AB),
-    babl_component_id (BABL_CIE_B),
-    NULL);
-}
index 0bf9c06fd668b1d918e89b09378721092fd252a5..73ecfe908d2272660bb3157741ea688ca6a43ba0 100644 (file)
@@ -349,7 +349,6 @@ formats (void)
     NULL);
 
   babl_format_new (
-    "name", "srgba",
     "id", BABL_SRGBA,
     babl_model_id     (BABL_RGBA_GAMMA_2_2),
     babl_type_id      (BABL_U8),
@@ -360,7 +359,6 @@ formats (void)
     NULL);
 
   babl_format_new (
-    "name", "rgba-float",
     "id",              BABL_RGBA_FLOAT,
     babl_model_id     (BABL_RGBA),
     babl_type_id      (BABL_FLOAT),
@@ -371,7 +369,6 @@ formats (void)
     NULL);
 
   babl_format_new (
-    "name", "rgba-double",
     "id",              BABL_RGBA_DOUBLE,
     babl_model_id     (BABL_RGBA),
     babl_type_id      (BABL_DOUBLE),
@@ -382,7 +379,6 @@ formats (void)
     NULL);
 
   babl_format_new (
-    "name", "rgb-float",
     "id", BABL_RGB_FLOAT,
     babl_model_id     (BABL_RGB),
     babl_type_id      (BABL_FLOAT),
index f03cf76f8727b94ef5e2deed83543051d3448c86..6a3e2aa6df73628ef892bbbafd32ef755d0582e4 100644 (file)
@@ -196,6 +196,23 @@ conversions (void)
 static void
 formats (void)
 {
+
+  babl_format_new (
+    "name",        "Y'CbCr u8 4:4:4",
+    "id",          BABL_YCBCR420,
+    "planar",
+    babl_model_id  (BABL_YCBCR),
+    babl_type_id   (BABL_U8_LUMA),
+    babl_sampling  (1, 1),
+    babl_component_id (BABL_LUMINANCE_GAMMA_2_2),
+    babl_type_id   (BABL_U8_CHROMA),
+    babl_sampling  (2, 2),
+    babl_component_id (BABL_CB), 
+    babl_sampling  (2, 2),
+    babl_component_id (BABL_CR),
+    NULL);
+  return;
+
   babl_format_new (
     "name",        "y'cbcr420",
     "id",          BABL_YCBCR420,